package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Transactional
@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        Map<String, Object> map = new HashMap<>();
        //今天的日期
        String today = DateUtils.parseDate2String(new Date());
        //本周一的日期
        String monday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //本月第一天日期
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        map.put("reportDate", today);
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        map.put("todayNewMember", todayNewMember);
        Integer totalMember = memberDao.findMemberTotalCount();
        map.put("totalMember", totalMember);
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(monday);
        map.put("thisWeekNewMember", thisWeekNewMember);
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);
        map.put("thisMonthNewMember", thisMonthNewMember);
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        map.put("todayOrderNumber", todayOrderNumber);
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        map.put("todayVisitsNumber", todayVisitsNumber);
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(monday);
        map.put("thisWeekOrderNumber", thisWeekOrderNumber);
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(monday);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);
        map.put("thisMonthOrderNumber", thisMonthOrderNumber);
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);
        map.put("thisMonthVisitsNumber", thisMonthVisitsNumber);
        List<Map> hotSetmeal = orderDao.findHotSetmeal();
        map.put("hotSetmeal",hotSetmeal);
        return map;
    }
}
